home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / tinycomm.arc / TINYCOMM.TXT < prev   
Encoding:
Text File  |  1986-12-13  |  26.3 KB  |  554 lines

  1.     Perhaps more than any other type of software, communications programs 
  2. are surrounded by an aura of mystery. If you've done any kind of programming
  3. you probably have a good idea what it is to write a word processing, database
  4. management, or spreadsheet program. Sure it'd be tough, but at least you know
  5. generally what's involved. Communications programs are not quite like that.
  6. The typical communications program puts such a heavy layer of software between
  7. you and the modem that its inner workings are often obscured.
  8.     Part of the problem results from the fact that communications soft-
  9. ware works in such close interdependence with the modem. Since the modem
  10. itself is programmable, the software is written to let the modem do part of
  11. the job. In one way, of course, that makes communications program simpler.
  12. unless you know what the modem is capable of doing, however, it may make
  13. understanding the related communications program more difficult. 
  14.     By letting your modem do its own thing, it's possible to write
  15. rudimentary communications programs with only a few lines of code. I'll show
  16. you how. Doing so, in fact, will help you both to explore the functions built
  17. into the modem and to discover how such small communications programs must be
  18. supplemented to provide the functionality of larger ones.
  19.  
  20.                            THE TINIEST COMM PROGRAM
  21.  
  22.  
  23.     Figure 1 shows how you can use DEBUG to create TINYCOMM, which i
  24. belive to be just about the smallest possible "functional" assembly language
  25. communication program. It's 49 bytes long. You'll see later the reason for the
  26. qualifying quotation marks when I call it "functional". TINYCOMM has many
  27. limitations, but, by strpping one part of the software/modem connection to the
  28. bare bones, TINYCOMM will help you explore some of the factors involved in
  29. modem communications software.
  30.  
  31. ===============================================================================
  32.  
  33.         debug
  34.         -A
  35.         XXXX:0100 MOV    DL,[005D]    ; GET PARAMETER
  36.         XXXX:0104 AND    DX,0001
  37.         XXXX:0108 MOV    AH,03        ; GET COMM STATUS
  38.         XXXX:010A INT    14
  39.         XXXX:010C TEST    AH,01        ; IF NOTHING, GO ON
  40.         XXXX:010F JZ    011F
  41.         XXXX:0111 MOV    AH,O2        ; READ CHARACTER
  42.         XXXX:0113 INT    14
  43.         XXXX:0115 PUSH    DX
  44.         XXXX:0116 MOV    DL,AL
  45.         XXXX:0118 MOV    AH,02        ; WRITE TO DISPLAY
  46.         XXXX:011A INT    21
  47.         XXXX:011C POP    DX
  48.         XXXX:011D JMP    0108        ; LOOP AROUND
  49.         XXXX:011F MOV    AH,0B        ; CHECK KEYBOARD
  50.         XXXX:0121 INT    21
  51.         XXXX:0123 OR    AL,AL
  52.         XXXX:0125 JZ    0108
  53.         XXXX:0127 MOV    AH,08        ; IF CHAR, READ IT
  54.         XXXX:0129 INT     21
  55.         XXXX:012B MOV    AH,01        ; SEND TO MODEM
  56.         XXXX:012D INT    14
  57.         XXXX:012F JMP    0108        ; LOOP AROUND
  58.         XXXX:0131
  59.         -N TINYCOMM.COM
  60.         -R CX
  61.         CX 0000
  62.         :31
  63.         -W
  64.         WRITING 0031 BYTES
  65.         -Q
  66.  
  67.  
  68.     Figure 1; if you have DOS's DEBUG.COM on your floppy or hard disk, you
  69. can create a 49-byte communications program called TINYCOMM by simply typing
  70. the lines above, starting from the DOS> prompt. Do not enter the addresses
  71. (XXXX:XXXX)--DOS will do that for you. Further, you dont need to type the
  72. semicolons and the comments after them.
  73. ===============================================================================
  74.  
  75.  
  76.  
  77.  
  78.     TINYCOMM uses the ROM BIOS Interrupt 14h to read incomming data from 
  79. the modem and to write outgoing data to the modem. It uses DOS Interrupt 21h
  80. function calls to read what you type at the keyboard and to write to the
  81. display. (Interrupt 14h is documented in the BIOS listing contained in the
  82. TECHNICAL REFERENCE manuals for the PC, XT, and AT. Interrupt 21h is documented
  83. in the DOS TECHNICAL REFERENCE manual.)
  84.     TINYCOMM first makes a status call to Interrupt 14h. If the status
  85. word returned in register AX indicates that the modem has received a
  86. character, TINYCOMM calls Interrupt 14h again to get the character, then
  87. displays it to the screen through DOS. If no character has been received yet,
  88. TINYCOMM goes on to check if anything has been typed at the keyboard. If so,
  89. it sends the typed character to the modem, again by Interrupt 14h. Then it
  90. goes back to the top. Notice that in both cases (reading the modem and reading
  91. the keyboard), TINYCOMM first checks if anything is ready. It doesn't want to
  92. get stuck waiting for a character from either source if none is available.
  93.     To use TINYCOMM, first turn on your modem and execute the PC-DOS MODE
  94. command to set it up for 300 bps, no parity, 8 data bits, and 1 stop bit:
  95.         
  96.             MODE COM1:300,N,8,1
  97.  
  98. Do not try 1,200 bps just yet. If your modem is connected to COM2, use that
  99. instead of COM1 in the MODE command above.
  100.     Now run TINYCOMM by entering:
  101.  
  102.             TINYCOMM
  103.  
  104. for a modem connected to COM1, or
  105.  
  106.             TINYCOMM 1
  107.  
  108. for COM2. You're not on-line yet, but you are in direct connection with your
  109. modem.
  110.  
  111.  
  112.  
  113.  
  114.  
  115.                            TALKING WITH YOUR MODEM
  116.  
  117.  
  118.     If you have a Hayes Smartmodem or compatible, you can now type in any
  119. of the AT attention codes documented in the user's guide or reference manual
  120. that came with the unit. For instance, with the Smartmodem 1200 or 1200B, you
  121. can enter:
  122.  
  123.             ATI0
  124.  
  125. to see the product's revision number,
  126.  
  127.             ATI1
  128.  
  129. for the modem's ROM checksum, and (with the 1200 but not the 1200B)
  130.  
  131.             ATI2
  132.  
  133. to check the integrity of its internal memory. This last instruction will
  134. return either OK or ERROR.
  135.     The "Smart" in Smartmodem refers to the modem's ability to interpret
  136. such AT codes and to send back appropriate responses. If your phone happens to
  137. ring while you're experimenting like this, TINYCOMM will display the word
  138. RING. Similarly, when using your normal communications programs, you may have
  139. noticed the words CONNECT or NO CARRIER displayed when you attempted to place
  140. a telephone call. These messages are not produced by your communications
  141. package; they all come straight from the modem, whose internal programming
  142. generates them.
  143.     Now let's make a call to the PC Magazine Interactive reader Service
  144. bulletin board. To do this, enter
  145.  
  146.             ATD 212-696-0360
  147.  
  148. If you have Touch-Tone service, you can use ATDT instead of ATD. (Even if you
  149. only have pulse dialing, you might try this command anyway: at the risk of
  150. having the telephone company read this, I'll tell you that I dont have
  151. Touch-Tone service but I have been dialing modems with touch-tone for years.)
  152.     If you have an external modem, You'll see your modem's OH (Off Hook)
  153. light go on and you'll hear the dialing. If the PC-IRS has a free line, you'll
  154. hear the PC-IRS carrier signal, quickly followed by your modem answering that
  155. carrier signal with its own. The CD (Carrier Detect) light on your modem will
  156. go on, you'll see the word CONNECT on the screen, and the the modem will go
  157. silent. you're on-line. (When you eventually want to break out of TINYCOMM,
  158. just press Cntrl-Break.)
  159.     If you get a busy signal, eventually your modem will give up and
  160. you'll get a NO CARRIER message on your screen. You can redial by typing:
  161.  
  162.             A/
  163.  
  164. which is the only Hayes control sequence that does not require a preceeding
  165. AT. 
  166.     Notice that TINYCOMM is doing very little in establishing this
  167. connection. Almost everything is handled by the modem itself. After you enter
  168. ATD and the phone number, the modem waits a couple of seconds for the dial
  169. tone before dialing the number and, if it doesn't detect a carrier, waits
  170. another period of time before sending back the NO CARRIER message and placing
  171. the phone back on the hook. You can set these two timings and many other
  172. variable aspects of the Smartmodem with modem control sequences (see S
  173. Registers table). Specifically, ATS6, followed by the time in seconds,
  174. controls the dial-tone wait; ATS7 similarly controls the carrier-detect wait.
  175. If you want to listen continuously to the carrier signals while you're
  176. on-line, you can enter ATM2 before making the call.
  177.  
  178. ===============================================================================
  179.  
  180.     
  181.                    S REGISTERS FOR HAYES-COMPATIBLE MODEMS
  182.  
  183. REGISTER    RANGE        DESCRIPTION                DEFAULT
  184.     
  185.                                      
  186. S0        0-225 rings        Ring to answer telephone on        0 or 1*
  187. S1        0-63/0-225rings    Signal quality/number of rings        -
  188. S2        0-127 ASCII        Escape code character            43(+)
  189. S3        0-127 ASCII        Character recognized as            13(CR)
  190.                 carriage return
  191. S4        0-127 ASCII        Character recognized as line feed    10(LF)
  192. S5        0-32,127 ASCII    Character recognized as backspace    8(BS)
  193. S6        2-225 sec.        Wait time for dial tone            2
  194. S7        1-60 sec.        Wait time for carrier            30
  195. S8        0-225 sec        Pause time caused by comma        2
  196. S9        1-225 1/10 sec.    Carrier detect response time        6
  197. S10        1-225 1/10 sec.    Delay between loss of carrier and    7
  198.                 hang up
  199. S11        50-255 msec.    Duration and spacing of Touch-tones    70
  200. S12        20-225 1/50 sec.    Escape code guard time            50
  201. S13         bit mapped        UART status register            -
  202. S14        bit mapped        Option register                -
  203. S15        bit mapped        Flag register                -
  204. S16        0,1,2,4        Test modes                0
  205.  
  206.  
  207.  
  208.     S-REGISTER TABLE; This is the S-Register set for the Hayes 1200.Any
  209. Hayes-compatible modem generally follows this command set. To set any of the
  210. registers, type ATS, the register number, the value you want to store, and hit
  211. the Enter Key. For instance, To set the S0 (auto answer) register to not answer
  212. (to Hayes, not answer means answer after zero rings), type ATS0=0<Enter>.
  213.  
  214. ===============================================================================
  215.  
  216.  
  217.  
  218.           
  219.     You can't enter these AT codes directly while you're on-line because
  220. the modem has no way of determining that you want to talk to it instead of the
  221. remote computer. To give commands while on-line, you first enter the Hayes
  222. escape sequence, which consists of three plus signs:
  223.  
  224.             +++
  225.  
  226. in a row typed quickly. You must wait a second before typing in the first plus
  227. sign, and wait a second afterwards before typing anything else. (The modem
  228. used these brief pauses to distinguish its escape sequence from three plus
  229. signs that may occur in transmitted data.) Having entered the +++ code
  230. properly, you'll get an OK from the moden indicating that you're in the
  231. command state instead of on-line. After you finish giving commands,
  232.  
  233.             ATO
  234.  
  235. returns the modem on-line.
  236.     if you want an escape sequence other than three plus signs, that too
  237. is programmable, as the Hayes manual explains.
  238.  
  239.  
  240.  
  241.                              SPLIT-LEVEL DUPLEX
  242.  
  243.     You'll notice that the TINYCOMM program uses the DOS Function Call 08h
  244. for reading your keystrokes. According to the DOS Technical Reference manual,
  245. however, this function call does not echo keystrokes to the screen. So  why
  246. then can you see your keystrokes as you type them?
  247.     Some of the characters you enter at the keyboard will be modem AT
  248. control sequences. The modem itself echoes these characters back, so TINYCOMM
  249. reads them as characters coming from the modem. You can turn off this modem
  250. echoing with the command:
  251.  
  252.             ATE0
  253.  
  254. Then when you type an AT code, you won't see it on the screen. Turn this type
  255. of modem echoing back on with:
  256.  
  257.             ATE1
  258.  
  259.     When you get on-line with a remote computer, however-whether it's an
  260. information service such as CompuServe, The Source, or Dow Jones
  261. News/Retrieval or with a bulletin board such as PC Magazine's IRS- the host
  262. computer echoes back most of the characters it receives. That's why you'll
  263. sense a slight delay between the time you type characters and their display on
  264. the screen.
  265.     This echoing is often innacurately referred to as full-duplex
  266. communication. A better term is remote-echo or echoplex. It requires that the
  267. two computers handle data differently. On your end, your communications
  268. program is reading the keyboard and sending the characters out to the modem
  269. without echoing them to the display. The host computer to which you are
  270. connected sends most of these characters back to you (with a few exceptions)
  271. in addition to sending you its own data.
  272.     On your receiving end, your program really can't tell whether a
  273. particular character was sent by the remote computer or echoed. If you also
  274. echoed back to the host computer everything you received, you'd really be
  275. thrown for a loop, because the characters would be continually tossed back and
  276. forth between the communicating computers.
  277.     When you use a modem to communicate with another PC or some other small
  278. computer, you'll probably want to use local echo (often innacurately called
  279. half-duplex). With local echo, each communication program handles the data the
  280. same way: by echoing keyboard characters to the screen a they are being typed
  281. and sending them out to the modem at the same time.
  282.     If you get on-line but find that you can't see what you type, it
  283. simply means that your software is set up for remote echo, but the computer
  284. you're talking with thinks you're using local echo. If you see two of every
  285. character you type, the cause is just the opposite.
  286.  
  287.  
  288.                    GETTING TWO PCs TALKING
  289.  
  290.  
  291.     If you want to connect with another pc over the telephone lines,
  292. you'll probably want to use local echo. You can do this in one of two ways.
  293. First, you can change TINYCOMM to use Function Call 01 instead of Function
  294. Call 08 for reading from the keyboard. A better way, however, is to instruct
  295. the modem itself to echo what you type by entering the control sequence:
  296.  
  297.             ATF0
  298.  
  299. You can later return to remote echo by typing:
  300.  
  301.             ATF1
  302.  
  303.     Another consideration that arises when two PCs are to communicate is
  304. the carrier frequencies. Two separate sets of frequencies are used by
  305. communicating modems. They are called "answer" and "originate" frequencies,
  306. but are really independent of which modem is making the phone call. When you
  307. call an information service or bulletin board, by convention your modem uses
  308. the originate frequencies. When you connect with another PC, however, you must
  309. decide which PC will use answer and which will use originate.
  310.     The easiest way to establish a connection between two PCs over the
  311. telephone lines is to first establish a voice communication. After you decide
  312. upon a common speed, data bits, parity, and stop bit and have everything set
  313. up, the person using originate frequencies enters
  314.  
  315.             ATD
  316.  
  317. and the other person using answer frequencies enters
  318.  
  319.             ATA
  320.  
  321. The answer carrier will sound first, then the tone from the originate modem.
  322. Now hang up the phone and start typing.
  323.     At this point another consideration arises that must be addressed: the
  324. problem of line feeds. When you press the Enter key, you generate only one
  325. character-ASCII 13, the Carriage Return. When your screen receives this this
  326. character,its proper response is simply to move the cursor to the beginning of
  327. the current line. However, the carriage rturn code does not tell the cursor to
  328. move down to the beginning of the next line: to move the cursor down one line,
  329. you need a Line Feed character (ASCII 10).
  330.     Most real communications programs will add the extra line feed, but
  331. TINYCOMM will not. Unless you want to change TINYCOMM to do this, you can get
  332. around it by typing a
  333.  
  334.             Ctrl-J (line feed)
  335.  
  336. after every Enter. Or, instead of pressing Enter, you can press
  337.  
  338.             Ctrl-M and Ctrl-J
  339.  
  340. Yes, you can get accustomed to it.
  341.  
  342.  
  343.                            THE AMAZING CTTY COMMAND
  344.  
  345.  
  346.     When you use TINYCOMM to go on-line with another microcomputer, you'll
  347. have a chance to try out one of the most interesting DOS commands, CTTY.
  348. TINYCOMM is ideal for CTTY for two reasons. First, TINYCOMM will not break the
  349. modem connection when you leave it by using Ctrl-Break. Many other
  350. communications programs will. Second, unlike other communications programs,
  351. TINYCOMM just uses Interrupt 14h instead of doing anything fancy. You'll later
  352. see that this is a deficiency when it comes to more serious communications
  353. work.
  354.     To try out CTTY, first use TINYCOMM to establish a modem connection
  355. with another microcomputer operated by a friend you would trust with your PC.
  356. This friend does not need to be using TINYCOMM or even an IBM PC.
  357.     Now instruct your friend to turn off his/her local echo. Then, exit
  358. TINYCOMM with
  359.  
  360.             Ctrl-Break
  361.  
  362. and at the DOS command level simply enter:
  363.  
  364.             CTTY COM1
  365.  
  366. (or COM2 if that's where your modem is). Your Dos prompt will then appear on
  367. your friend's screen and not on yours. If your friend enters DIR, you won't
  368. see it but your disk drives will whir, and the directory listing wil appear on
  369. the other computer's diplay. (Now you see why this person should be someone
  370. you trust. That Dir could just as easily be a DEL *.*).
  371.     After your friend has been fully amused by using your PC over the
  372. telephone line, he/she can enter:
  373.  
  374.             CTTY CON
  375.  
  376. At that point your DOS prompt will appear back on your screen, and you can
  377. reenter your on-line communication.
  378.  
  379.  
  380.                              WHAT'S GOING ON HERE?
  381.  
  382.  
  383.     CTTY allows another device (in this case the communications port) to
  384. be substituted for DOS's normal standard input device (the keyboard) and
  385. standard output device (the screen). Any program that uses DOS function calls
  386. for keyboard and screen display will then use this alternative device instead
  387. of the default CON device. Any of the DOS internal commands (with the
  388. exception of CLS) will work, as well as most of the DOS programs such as
  389. CHKDSK, EDLIN, and DEBUG.
  390.     If your friend tries to run Lotus 1-2-3, however, it will appear on
  391. your screen and accept input from your keyboard. This is because 1-2-3 (like
  392. most spreadsheet and word processing programs) does not use DOS for keyboard
  393. input and screen output. The BASIC interpreter also deos not use use DOS for
  394. keybaord and screen and will not work with CTTY.
  395.     For a rel treat, If your friend's communication program supports
  396. terminal emulation (ANSI or VT-100, for example), you can patch Wordstar to
  397. tell it that it's not running on an IBM-PC, in which case it will use DOS for
  398. the keyboard and screen. you then patch Wordstar to use screen control
  399. sequences for positioning the cursor and anything else the terminal emulation
  400. program allows. Your friend can then use Wordstar over the telephone lines,
  401. even on a Macintosh (on a Macintosh?). To work with Wordstar at a 300-bps
  402. screen update rate is a facinating experience and one that will allow you to
  403. catch a few winks after every Ctrl-C (Page Down).
  404.  
  405.  
  406.             THE LIMITATIONS OF TINYCOMM
  407.  
  408.  
  409.     When I introduced TINYCOMM above, I said it would produce some
  410. problems. If you've been using it to communicate with information services or
  411. bulletin boards, you've probably already notices some of these oddities.
  412.     Although TINYCOMM is programmed in assembly language and thus, in
  413. theory, is vey fast, you can't use it at 1,200 bps. Don't beleive me? Try it
  414. out by changing the bps setting with MODE and connecting to an information
  415. service or bulletin board. If you start at the top of the screen, things seem
  416. to go fairly well at first, but once you get down to the bottom of the screen,
  417. you'll notice that TINYCOMM starts missing the first few letters of each line
  418. that is sent from the remote computer.
  419.     COmmunications programs do not normally use Interupt14h, as TINYCOMM
  420. does. This is because Interrupt 14h is missing two very important ingredients
  421. of normal communications software: buffering and interrupt control. Instead,
  422. TINYCOMM simply polls the serial port for data, and if it can't do it's
  423. polling fast enough, it misses characters. This is what happens when the
  424. screen scrolls at 1,200 bps. During the time it takes the screen to scroll,
  425. several characters at the start of the line are coming through.
  426.     Real communications programs don't have this problem because they use
  427. the serial port's interrupts and buffer all the data. Let's see how this works.
  428.  
  429.  
  430.                                 THE UART PORTS
  431.  
  432.  
  433.     The Interrupt 14h code in the ROM BIOS is not very big as assembly
  434. language goes-just a bit over two pages in the Technical Reference manual. It
  435. works by accessing the 8250 UART (Universal Asynchronous Receiver Transmitter)
  436. through I/O ports. These ports are at addresses 3F8h through 3FFh for COM1 and
  437. 2F8h through 2FFh for COM2.
  438.     Where you can find documentation on these serial I/O ports depends
  439. upon what type of modem you have. The Hayes 1200B internal board modem comes
  440. with a Hardware Reference Manual that discusses the ports in detail, since the
  441. UART is part of the board. The standalone modem connects by cable to an
  442. asynchronous communications port and the registers involved are also discussed
  443. in the documentation for the serial board in any of the Technical Reference
  444. manuals for the PC.
  445.     If you are new to UART programming and want to learn how to do it
  446. right (instead of using Interrupt 14h), be prepared to spend many long hours
  447. with these few pages of documentation-studying the Interrupt 14h code until
  448. you understand every single line of it-and in doing lots of experimentation.
  449.     The greatest advantage to programming the UART directly through the
  450. I/O ports is the ability to enable its interrupts. Instead of polling the UART
  451. status, as TINYCOMM does, a real communications program is driven by hardware
  452. interrupts. The uart can be programmed to generate an interrupt whenever it
  453. receives a character or is ready to send another character.
  454.     A real communications program will also buffer outgoing and incoming
  455. data. When a new character is received, the interrupt routine stores it in a
  456. circular buffer. When the main communications program access incoming data, it
  457. retrieves it from this buffer instead of from the port.
  458.     Similarly, typed keyboard input goes into another circular buffer. As
  459. the UART sends this data, it generates a hardware interrupt when it's done
  460. with one and ready for another. That way, the main program can shovel a lot of
  461. data to the buffer and not wait for the UART to transmit it all. (If you want
  462. to try programming something like this, you might also benefit from looking at
  463. the code for keyboard Interrupts 9 and 16h, in the ROM BIOS listing. That will
  464. show you how circular buffers work.)
  465.  
  466.  
  467.                              THE SOLUTION IS BASIC
  468.  
  469.  
  470.     If we were to add direct UART programming, interrupt control, and
  471. buffering to TINYCOMM, it would not stay tiny for long.
  472.     So let's change direction. Let's use some software supplied with
  473. PC-DOS that already has built-in data buffering and interrupt-driven
  474. communication logic. You didn't know you already had such software? Sure you
  475. do. It's all there in the BASIC interpreter.
  476.     Figure 2 shows another simple communications program called BASCOMM.
  477. Let me say first that this program also has some deficienciies, some of which
  478. are repeated from TINYCOMM, some of which are new. Otherwise it works the same
  479. as TINYCOMM.  You enter the modem control sequences directly nad press
  480. Ctrl-Break when you want to get out.
  481.  
  482.  
  483. ===============================================================================
  484.  
  485. 10 OPEN "COM2:300,E,7,1" AS #1
  486. 15 OPEN "SCRN:" FOR OUTPUT AS #2
  487. 20 IF NOT EOF(1) THEN PRINT #2,INPUT$(1,1);
  488. 30 A$ = INKEY$ : IF A$ <> "" THEN PRINT #1,A$;
  489. 40 GOTO 20
  490.  
  491.  
  492.  
  493. Figure 2; A small comunications program written in BASIC. More sophisticated
  494. BASIC communications programs are shown in the IBM BASIC manual and included
  495. with PC-DOS (COMM.BAS). PC-Talk III is an example of an extremely
  496. sophisticated BASIC program.
  497.  
  498. ===============================================================================
  499.  
  500.  
  501.     The new problem you'll encounter is double spacing of all incoming
  502. lines of data. This is BASIC "helping" you out by sticking a line feed onto
  503. each carriage return. Unfortunately, in remote-echo communications, you dont
  504. want that extra line feed.
  505.     You'll also notice (as you probably did with TINYCOMM) that at various
  506. times you'll see two odd characters appear on your display: the double
  507. exclamation point (ASCII 19 0r Ctrl-S) and the left pointing triangle (ASCII
  508. 17 or Ctrl-Q). These characters have formal ASCII names of DC3 and DC1. The DC
  509. stands for Device Control, but in modem communications they are more commonly
  510. referred to as XOFF and XON.
  511.     When your communications program receives a Ctrl-S (XOFF) character,
  512. that is a signal to tell you that your program to stop sending data. The
  513. computer you are connected to is telling you (by sending XOFF) that is doing
  514. something else and may suffer a buffer overflow if you continue. Likewise,
  515. when the remote computer sends a Ctrl-Q (XON), it is signalling that it can
  516. resume receiving data from you.
  517.     Your communications program might also want to send XOFF and XON to
  518. the remote computer. With the simple BASCOMM program, you can do that
  519. yopurself simply by pressing Ctrl-S and Ctrl-Q. Generally you stop the flow of
  520. data to give you time to read it.
  521.     XOFF and XON become more important during ASCII file transfers. For
  522. instance, if you add some file-transfer logic to the BASCOMM program. you must
  523. send XOFF when beginning a disk access. This prevents a buffer overflow while
  524. you are using the disk. When you are done with the file access and have enough
  525. characters from the buffer to deplete it, you can then send an XON to signal
  526. that data transfeer may be resumed.
  527.     BASIC has several other built-in functions that will help you manage
  528. the input buffer. these include LOC (which tells you the number of characters
  529. in the input buffer) and LOF (the buffer's free space).
  530.     At this point, however, instead of fixing up BASCOMM to include these
  531. additional features, let me direct you to Appendix F of IBM's BASIC 2.0 manual
  532. or to Appendix C of the BASIC 3.0 manual. Under the heading"An Example
  533. Program," you'll find a 20-line BASIC program (documented with lots of
  534. comments) that handles both line feed problems and the XON/XOFF protocol.
  535.     PC-DOS also comes with a free communications program called COMM.BAS.
  536. This one has a menu to set thte bps rate, parity, and data bits, but it's
  537. really just a fancy version of the small program shown in the BASIC manual.
  538.     Once you print out COMM.BAS and get familiar with its workins, your
  539. next step can be to look at a real communications program written entirely in
  540. BASIC: the famous freeware program, PC-TALK III.  If you use this program, you
  541. probably use the compiled version, but the 800 tightly coded lines of BASIC
  542. source code are available on many bulletin boards.
  543.  
  544.  
  545.             IN PRAISE OF SMALL PROGRAMS
  546.  
  547.  
  548.     Although it's tough to beat the power of several recent (and large)
  549. communications programs, such as Ascom or Microsoft Access, you may find a
  550. samller communications program is sometimes preferable-for the same reasons
  551. that people sometimes prefer riding a bicycle to driving a car.  You're more
  552. in control, closer to the ground, unsheltered, and feel every bump.  It's more
  553. adventurous and also, of course, much more fun.
  554.